<template>
  <div class="app-content">
    <h2 class="font-500 mb-40px">上传设置</h2>
    <div v-if="!defaultApp?.id || err.code == -1">
      <el-empty :description="err.msg" />
    </div>
    <template v-else>
      <div v-if="authType === 1">
        <el-empty description="当前为服务商上传，无需配置" />
      </div>
      <div v-else v-loading="loading" class="min-h-500px">
        <dk-form :form-data="formData" :is-dialog="false" />
      </div>
    </template>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, inject } from 'vue'
import { useUserStore } from '@/stores/user'
import { getPlaid, getAppid } from '@/composables/useSystem'
import { getAppSettingForm } from '@/api/platform/app/app_setting'

defineOptions({
  name: 'AppUploadSetting'
})

// 注入的应用信息
const defaultApp = inject('defaultApp')

// 响应式数据
const formData = ref(null)
const loading = ref(true)
const plaid = ref(getPlaid())
const err = ref({})

// store
const userStore = useUserStore()

// 计算属性
const userinfo = computed(() => userStore.user)
const authType = computed(() => defaultApp.value?.server_config?.auth_type || 0)

// 生命周期
onMounted(() => {
  if (authType.value !== 1) {
    getAppSettingForm(plaid.value, defaultApp.value.id, 'upload')
      .then((res) => {
        formData.value = res.data
        loading.value = false
      })
      .catch((res) => {
        loading.value = false
        err.value = res
        // this.$router.push('/app/addon?p=' + plaid.value)
      })
  } else {
    loading.value = false
  }
})
</script>

<style lang="scss" scoped></style>
